package test.singleton;

/**
 * 懒汉式
 */
public class Girlfriend {
    private Girlfriend() {
    }

    /**
     * volatile 避免指令重排
     */
    private static volatile Girlfriend instance = null;

    // 补充
    // 解决线程的不安全性
    public static synchronized Girlfriend getInstance() {
        if (instance == null) {
            instance = new Girlfriend();
        }
        return instance;
    }

}
